/*
 * EpsilonPolicy.cc
 *
 *  Created on: 11 jan. 2011
 *      Author: Frans
 */

#include "EpsilonPolicy.h"
#include "Direction.h"
#include "stdlib.h"
#include <cstddef>
#include <stdio.h>

EpsilonPolicy::EpsilonPolicy(double epsilon) {
	this->epsilon = epsilon;
}

int EpsilonPolicy::getPreferredDirection(double north, double east, double south,
		double west) {

	float r = (float) rand() / (float) RAND_MAX;
	if (r < this->epsilon) {
		int index = (float) rand() / (float) RAND_MAX * 4;
		return index;
	} else {
		int result = 0;
		double currentqvalue = north;
		if (east > currentqvalue) {
			currentqvalue = east;
			result = 1;
		}
		if (south > currentqvalue) {
			currentqvalue = south;
			result = 2;
		}
		if (west > currentqvalue) {
			currentqvalue = west;
			result = 3;
		}
		return result;
	}
}
